<template>
	<u-gap height="120"></u-gap>
	<u-gap height="120" v-if="!isGuanjia && detail.status != 4 && props.houseType == 3"></u-gap>
	<u-gap height="120" v-if="!isGuanjia && detail.status != 4 && props.houseType == 1"></u-gap>
	<view class="fixed-bottom u-p-20 bgw" v-if="isGuanjia && (isUpdate||isCreateOrder)">
		<view class="u-flex">
			<view class="u-flex-1 u-p-l-10 u-p-r-10" v-if="isUpdate">
				<u-button @click="toEdit" type="primary" :plain="true" class="btn-block">编辑信息</u-button>
			</view>
			<view class="u-flex-2 u-p-l-10 u-p-r-10" v-if="isCreateOrder">
				<u-button @click="toOrderAdd" type="primary" class="btn-block">创建订单</u-button>
			</view>
		</view>
	</view>
	<view class="fixed-bottom u-p-20 bgw" v-if="!isGuanjia">
		<!-- 房源状态【1-待审核2-已通过（未上架）3-未通过4-待出租（已上架）5-已出租】 -->
		<!-- 房源状态【1-待审核2-已通过3-未通过4-销售中5-待签约6-已签约7-过户异常8-已售】 -->
		<view v-if="detail.status != 4 && props.houseType == 3">
			<u-alert-tips type="error" description="该房源非待出租状态..."></u-alert-tips>
			<u-gap height="20"></u-gap>
		</view>
		<view v-if="detail.status != 4 && props.houseType == 1">
			<u-alert-tips type="error" description="该房源非销售中的状态..."></u-alert-tips>
			<u-gap height="20"></u-gap>
		</view>

		<view class="u-flex">
			<view class="u-p-l-20 u-p-r-15 u-flex" style="flex-direction:column" @click="toYuyue">
				<image src="/static/images/icon-yykf-mini.png" mode="aspectFit" class="icon-image"></image>
				<view class="u-font-22 u-p-t-5">预约看房</view>
			</view>
			
			<view class="u-p-l-15 u-p-r-15" v-if="props.houseType == 2">
				<link-tel :link-user-type="3" :house-id="props.houseId" :house-type="props.houseType">
					<view class="u-flex" style="flex-direction:column">
						<image src="/static/images/icon-lxfd-mini.png" mode="aspectFit" class="icon-image"></image>
						<view class="u-font-22 u-p-t-5">联系平台</view>
					</view>
				</link-tel>
			</view>
			<!-- 《2月11日对接》4、隐藏联系房东按钮，现在的功能逻辑是开通会员可以拨打房东电话，此功能需要放下下一阶段进行，现阶段仅能让用户联系管家，通过管家进行成交 -->
			<!-- 20250211注释 如需要取消注释即可-->
			<!-- <view class="u-p-l-15 u-p-r-15" v-else>				
				<link-tel :link-user-type="1" :house-id="props.houseId" :house-type="props.houseType">
					<view class="u-flex" style="flex-direction:column">
						<image src="/static/images/icon-lxfd-mini.png" mode="aspectFit" class="icon-image"></image>
						<view class="u-font-22 u-p-t-5">联系房东</view>
					</view>
				</link-tel>
			</view> -->
			<view class="u-flex-1 u-p-l-10 u-p-r-10">
				<link-tel :link-user-type="2" :house-id="props.houseId" :house-type="props.houseType">
					<u-button style="pointer-events: none;" type="primary" :plain="true" class="btn-block">联系管家</u-button>
				</link-tel>
			</view>
			<view class="u-flex-1 u-p-l-10 u-p-r-10">
				<u-button open-type="contact" type="primary" class="btn-block">在线咨询</u-button>
			</view>
		</view>
	</view>

	<u-picker :params="pickerParams" v-model="pickerShow" mode="time" @confirm="confirmPicker"></u-picker>
	<!-- default-time="2025-07-02 13:01" start-year="2024" -->
</template>

<script setup>
	import store from '@/store/index.js';
	import {
		ref,
		reactive,
		computed,
		onMounted,
		getCurrentInstance,
		watch,
		onUnmounted
	} from 'vue'
	const {
		proxy
	} = getCurrentInstance()
	const {
		nav,
		navLogin,
		navGLogin,
		modal,
		
	} = proxy.$util;
	const isLogin = computed(() => {
		return store.getters.get_isLogin
	})
	const props = defineProps({
		isGuanjia: {
			type: Boolean,
			default: false,
		},
		isCreateOrder:{
			type: Boolean,
			default: false,
		},
		isUpdate:{
			type: Boolean,
			default: false,
		},
		houseType: {
			type: [String, Number],
			default: '',
		},
		houseId: {
			type: [String, Number],
			default: '',
		},
		detail:{
			type: Object,
			default: {},
		}
	})
	const telNumber = ref();
	const tel = () =>{
		uni.makePhoneCall({
			phoneNumber:telNumber.value
		});
	}
	onMounted(()=>{
		getData();
	})
	
	const getData = () => {
		// uni.showLoading({
		// 	title: '加载中'
		// });
		proxy.$u.api.commonServiceTel().then(res => {
			let {
				data,
				code,
				msg
			} = res;
			if (code == 200) {
				telNumber.value = data;
			}else {
				uni.$u.toast(msg || '错误');
			}
		})
	}
	const pickerParams = {
		year: true,
		month: true,
		day: true,
		hour: true,
		minute: true,
		// second: false
	};
	const pickerShow = ref(false)
	
	const toYuyue = () => {
		if (!isLogin.value) {
			modal({
				content: '您未登录!',
				confirmColor: '#249CFF',
				showCancel: false,
			}).then(() => {
				nav('/pages/my/my')
			})
			return false;
		}
		pickerShow.value = true;
	}
	defineExpose({
		toYuyue
	})
	const confirmPicker = (e) => {
		let {
			day,
			hour,
			minute,
			month,
			year
		} = e;
		let yuyue_time = [year, month, day].join('-') + ' ' + [hour, day].join(':');
		uni.showLoading({
			title: '提交中',
			mask: true
		});
		proxy.$u.api.yuYueLook({
			house_type: props.houseType,
			house_id: props.houseId,
			yuyue_time: yuyue_time
		}).then(res => {
			let {
				code,
				msg,
				data
			} = res;
			if (code == 200) {
				modal({
					content: res.msg || '预约成功',
					showCancel: false
				})
			} else {
				modal({
					content: res.msg || '错误',
					showCancel: false
				})
			}
		})
	}
	// 创建订单
	const toOrderAdd = () => {
		if(props.houseType == 3){
			navGLogin('/pagesGuanjia/rentOrderEdit/rentOrderEdit',{
				id:props.detail.rent_house_id,
				sn:props.detail.rent_house_sn
			})
		}else{
			navGLogin('/pagesGuanjia/sellOrderEdit/sellOrderEdit',{
				id:props.detail.old_house_id,
				sn:props.detail.old_house_sn,
				houseType:props.houseType
			})
		}
	}
	const toEdit = () =>{
		// isGuanjia
		if(props.houseType == 3){
			navGLogin('/pagesSub/rentEdit/rentEdit',{
				id:props.detail.rent_house_id,
				isGuanjia:1
			})
		}
		if(props.houseType == 1){
			navGLogin('/pagesSub/secondhandEdit/secondhandEdit',{
				id:props.detail.old_house_id,
				isGuanjia:1
			})
		}
		
	}
</script>

<style lang="scss" scoped>

</style>